//
//  BaseView.m
//  ProjectExtension
//
//  Created by Apple on 2020/1/8.
//  Copyright © 2020 lidianchao. All rights reserved.
//

#import "BaseView.h"
#import "Config.h"
#import "UILabel+MyLabel.h"
static BaseView *instance = nil;
@implementation BaseView
+ (BaseView *)getInstance
{
    static dispatch_once_t pred;
    dispatch_once(&pred, ^{
        instance = [[BaseView alloc] init];
    });
    return instance;
}
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if(self){
        
    }
    return self;
}
/**
 *  创建imageView
 */
- (UIImageView *)createImageViewWithFrame:(CGRect)frame withImage:(UIImage *)image {
    
    UIImageView *imageView = [[UIImageView alloc] initWithFrame:frame];
    
    imageView.image = image;
    
    return imageView;
}
- (UITableView *)createTabelViewAndSetDelegateClass:(id)class  andIdentifier:(NSString *)identifier isPlain:(BOOL )isPlain delegate:(nonnull id)delegate{
    
    UITableView *tabel = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, DeviceWidth, DeviceHeight-kIs_iPhoneX_height) style:isPlain?UITableViewStylePlain:UITableViewStylePlain];
    
    tabel.delegate = delegate;
    
    tabel.dataSource = delegate;
    tabel.opaque = YES;//原因是这会使系统用一个最优的方式渲染这些views
    tabel.separatorStyle = UITableViewCellSeparatorStyleNone;
    tabel.backgroundColor = [UIColor clearColor];
    if (class) {
        [tabel registerClass:class forCellReuseIdentifier:identifier];
    }
    //去除动画异常
    if (@available(iOS 11.0, *)) {
        tabel.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
        tabel.estimatedRowHeight =0;
        tabel.estimatedSectionHeaderHeight =0;
        tabel.estimatedSectionFooterHeight =0;
    }
    [self setExtraCellLineHidden:tabel];
    return tabel;
}
- (UIView *)createNoMoreViewWithFrame:(CGRect)frame withText:(NSString *)string {
    
    UIView *view = [[UIView alloc] initWithFrame:frame];
    view.backgroundColor = [UIColor clearColor];
    UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, DeviceWidth*0.26, DeviceWidth*0.26)];
    imageView.image = [UIImage imageNamed:@"noHistory"];
    imageView.center = CGPointMake(DeviceWidth/2, (CGRectGetMidY(frame)>200)?((CGRectGetMidY(frame)-(NavigationHeight+TabBarHeight))):(CGRectGetMidY(frame)-40));
    [view addSubview:imageView];
    CGFloat leftDistance = 15;
    UILabel *creat = [UILabel createLabelWithFrame:CGRectMake(leftDistance, CGRectGetMaxY(imageView.frame)+10, DeviceWidth-leftDistance*2, 20) title:string textColor:K_9EAABD_color isCenter:YES font:12 andHaveUnderLine:NO board:NO];
    [view addSubview:creat];
    
    return view;
}
#pragma -mark pricateMethod
//去除底部多余cell
-(void)setExtraCellLineHidden: (UITableView *)tableView
{
    UIView *view = [UIView new];
    
    view.backgroundColor = [UIColor clearColor];
    
    [tableView setTableFooterView:view];
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
